home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / documents / X / pidinfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  970 b   |  39 lines

  1. /*
  2.  *   pidinfo.c:
  3.  *
  4.  *   very simple /proc User+Sys Measurer utility program example.
  5.  *
  6.  *   ascii text source code format from page # 65 of 
  7.  *   the "X Performance and You" showcase slides from toolbox/documents/X 
  8.  *
  9.  * cc -o pidinfo pidinfo.c 
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <errno.h>
  14. #include <fcntl.h>
  15. #include <sys/procfs.h>
  16.  
  17. main(int argc, char **argv)
  18. {
  19.    char buf[32];
  20.    int fd, tries;
  21.    prstatus_t status;
  22.  
  23.    sprintf(buf, "/proc/%d", atoi(argv[1]));
  24.    if ((fd=open(buf, O_RDWR)) == -1) exit(1);
  25.    for(;;) {
  26.        tries = 0;
  27.        while ((tries < 5) && (ioctl(fd, PIOCSTATUS, &status) == -1) &&
  28.           (errno == EAGAIN))
  29.            tries++;
  30.        if (tries == 5) exit(2);
  31.        printf(">> snap of sys and usr for %s\n", buf);
  32.        printf("   usr = %5d.%03d\n",
  33.        status.pr_utime.tv_sec, status.pr_utime.tv_nsec/1000000);
  34.        printf("   sys = %5d.%03d\n",
  35.        status.pr_stime.tv_sec, status.pr_stime.tv_nsec/1000000);
  36.        sleep(1);
  37.    }
  38. }
  39.